[리눅스] NGINX 및 PHP | 您所在的位置:网站首页 › nginx main › [리눅스] NGINX 및 PHP |
NGINX 및 PHP-FPM 액세스 로그 설정
nginx access logs format
$ vim /etc/nginx/nginx.conf
...
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$remote_addr"'
' REQ_TIME: $request_time s - CONNECT_TIME: $upstream_connect_time s - PHP-FPM_STATUS: $upstream_status';
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
php-fpm access logs format
$ vim /etc/php-fpm.d/www.conf
...
access.log = /var/log/php-fpm/www-access.log
access.format = "[%t] %m %{REQUEST_SCHEME}e://%{HTTP_HOST}e%{REQUEST_URI}e %f pid:%p took:%ds mem:%{mega}Mmb cpu:%C%% status:%s {%{REMOTE_ADDR}e|%{HTTP_USER_AGENT}e}"
$ php-fpm -t
[15-Oct-2020 14:19:25] NOTICE: configuration file /etc/php-fpm.conf test is successful
NGINX 로그 포맷
The log format can contain common variables, and variables that exist only at the time of a log write:$bytes_sentthe number of bytes sent to a client$connectionconnection serial number$connection_requeststhe current number of requests made through a connection (1.1.18)$msectime in seconds with a milliseconds resolution at the time of the log write$pipe“p” if request was pipelined, “.” otherwise$request_lengthrequest length (including request line, header, and request body)$request_timerequest processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client$statusresponse status$time_iso8601local time in the ISO 8601 standard format$time_locallocal time in the Common Log FormatThe ngx_http_upstream_module module supports the following embedded variables:$upstream_addrkeeps the IP address and port, or the path to the UNIX-domain socket of the upstream server. If several servers were contacted during request processing, their addresses are separated by commas, e.g. “192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock”. If an internal redirect from one server group to another happens, initiated by “X-Accel-Redirect” or error_page, then the server addresses from different groups are separated by colons, e.g. “192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock : 192.168.10.1:80, 192.168.10.2:80”. If a server cannot be selected, the variable keeps the name of the server group.$upstream_bytes_receivednumber of bytes received from an upstream server (1.11.4). Values from several connections are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_bytes_sentnumber of bytes sent to an upstream server (1.15.8). Values from several connections are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_cache_statuskeeps the status of accessing a response cache (0.8.3). The status can be either “MISS”, “BYPASS”, “EXPIRED”, “STALE”, “UPDATING”, “REVALIDATED”, or “HIT”.$upstream_connect_timekeeps time spent on establishing a connection with the upstream server (1.9.1); the time is kept in seconds with millisecond resolution. In case of SSL, includes time spent on handshake. Times of several connections are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_cookie_namecookie with the specified name sent by the upstream server in the “Set-Cookie” response header field (1.7.1). Only the cookies from the response of the last server are saved.$upstream_header_timekeeps time spent on receiving the response header from the upstream server (1.7.10); the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_http_namekeep server response header fields. For example, the “Server” response header field is available through the $upstream_http_server variable. The rules of converting header field names to variable names are the same as for the variables that start with the “$http_” prefix. Only the header fields from the response of the last server are saved.$upstream_queue_timekeeps time the request spent in the upstream queue (1.13.9); the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_response_lengthkeeps the length of the response obtained from the upstream server (0.7.27); the length is kept in bytes. Lengths of several responses are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_response_timekeeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.$upstream_statuskeeps status code of the response obtained from the upstream server. Status codes of several responses are separated by commas and colons like addresses in the $upstream_addr variable. If a server cannot be selected, the variable keeps the 502 (Bad Gateway) status code.$upstream_trailer_namekeeps fields from the end of the response obtained from the upstream server (1.13.10).
http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format http://nginx.org/en/docs/http/ngx_http_upstream_module.html PHP-FPM 로그 포맷; The access log format. ; The following syntax is allowed; %%: the '%' character; %C: %CPU used by the request; it can accept the following format:; - %{user}C for user CPU only; - %{system}C for system CPU only; - %{total}C for user + system CPU (default); %d: time taken to serve the request; it can accept the following format:; - %{seconds}d (default); - %{miliseconds}d; - %{mili}d; - %{microseconds}d; - %{micro}d; %e: an environment variable (same as $_ENV or $_SERVER); it must be associated with embraces to specify the name of the env; variable. Some exemples:; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e; %f: script filename; %l: content-length of the request (for POST request only); %m: request method; %M: peak of memory allocated by PHP; it can accept the following format:; - %{bytes}M (default); - %{kilobytes}M; - %{kilo}M; - %{megabytes}M; - %{mega}M; %n: pool name; %o: ouput header; it must be associated with embraces to specify the name of the header:; - %{Content-Type}o; - %{X-Powered-By}o; - %{Transfert-Encoding}o; - ....; %p: PID of the child that serviced the request; %P: PID of the parent of the child that serviced the request; %q: the query string; %Q: the '?' character if query string exists; %r: the request URI (without the query string, see %q and %Q); %R: remote IP address; %s: status (response code); %t: server time the request was received; it can accept a strftime(3) format: %d/%b/%Y:%H:%M:%S %z (default); %T: time the log has been written (the request has finished); it can accept a strftime(3) format: %d/%b/%Y:%H:%M:%S %z (default); %u: remote user
|
CopyRight 2018-2019 实验室设备网 版权所有 |